package com.rxkj.controller;


import com.rxkj.entity.gnss.*;
import com.rxkj.service.GnssDataService;
import com.rxkj.utils.PageData;
import com.rxkj.utils.ResponseResult;
import io.swagger.annotations.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

import static com.rxkj.utils.ResponseResult.success;

/**
 * GNSS数据API
 *
 * @author alex
 * @date 2022-10-29 15:10:41
 */
@Api(tags = "GNSS位移监测")
@RestController
@RequestMapping(value = "/gnss-api")
public class GnssDataController {

    private static Logger logger = LoggerFactory.getLogger(GnssDataController.class);

    @Autowired
    private GnssDataService gnssDataService;


    @ApiOperation("站点实时数据分页")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "currentPage", required = true, value = "当前页码"),
            @ApiImplicitParam(name = "pageSize", required = true, value = "每页条数"),
            @ApiImplicitParam(name = "deviceName", required = false, value = "设备名称")
    })
    //@RoleLevel(2)
    @GetMapping("/initDevDataPage")
    public ResponseResult<PageData<GnssDataVO>> initDevDataPage(@RequestParam("currentPage") int currentPage,
                                                                @RequestParam("pageSize") int pageSize,
                                                                @RequestParam(value = "deviceName", required = false) String deviceName){
        PageData<GnssDataVO> qe = gnssDataService.initDevDataPage(currentPage, pageSize, deviceName);
        return qe.getRows().size() > 0?(ResponseResult<PageData<GnssDataVO>>) ResponseResult.success("查询成功", qe) : (ResponseResult<PageData<GnssDataVO>>) ResponseResult.success("未查询到数据...", qe);
    }

    @ApiOperation("站点历史数据分页")
    @ApiImplicitParam(name = "queryGnss", value = "gnss数据查询条件")
    //@RoleLevel(2)
    @PostMapping("/getDevDataPage")
    public ResponseResult<PageData<GnssDataVO>> getDevDataPage(@RequestBody QueryGnssVO queryGnss){
        PageData<GnssDataVO> qe = gnssDataService.getDevDataPage(queryGnss);
        return qe.getRows().size() > 0?(ResponseResult<PageData<GnssDataVO>>) ResponseResult.success("查询成功", qe) : (ResponseResult<PageData<GnssDataVO>>) ResponseResult.success("未查询到数据...", qe);
    }

    @ApiOperation("站点图表数据")
    @GetMapping("/getGnssChartDataByDveId")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "startTime", required = true, value = "开始时间"),
            @ApiImplicitParam(name = "endTime", required = true, value = "结束时间"),
            @ApiImplicitParam(name = "deviceId", required = true, value = "deviceId")
    })
    //@RoleLevel(2)
    public ResponseResult<List<GnssDataVO>> getGnssChartDataByDveId(@RequestParam(value = "startTime", required = true) String startTime,
                                                                    @RequestParam(value = "endTime", required = true) String endTime,
                                                                    @RequestParam(value = "deviceId", required = true) String deviceId){
        List<GnssDataVO> qe = gnssDataService.getGnssChartDataByDveId(startTime, endTime, deviceId);
        return qe.size() > 0? (ResponseResult<List<GnssDataVO>>) ResponseResult.success("查询成功", qe) : (ResponseResult<List<GnssDataVO>>) ResponseResult.success("未查询到数据...", qe);
    }

    /**
     * 分页条件查询gnss位移数据
     *
     * @param queryGnss 查询gnss
     * @return {@link ResponseResult}<{@link PageData}<{@link GnssDataVO}>>
     */
    @ApiOperation("分页条件查询gnss位移数据")
    @ApiImplicitParam(name = "queryGnss", value = "gnss数据查询条件")
    //@RoleLevel(2)
    @PostMapping("/getGnssDataPage")
    public ResponseResult<PageData<GnssDataVO>> getGnssDataPage(@RequestBody QueryGnssVO queryGnss){
        PageData<GnssDataVO> qe = gnssDataService.getGnssDataPage(queryGnss);
        return qe.getRows().size() > 0?(ResponseResult<PageData<GnssDataVO>>) ResponseResult.success("查询成功", qe) : (ResponseResult<PageData<GnssDataVO>>) ResponseResult.success("未查询到数据...", qe);
    }

    /**
     * 下拉选数据，注意下拉选有三级联动的操作，此操作由前端完成
     *
     * @return {@link ResponseResult}<{@link Map}<{@link String}, {@link Object}>>
     */
    @ApiOperation("三级联动下拉选数据")
    //@RoleLevel(2)
    @GetMapping("/getSelectDownData")
    @ApiResponses({
            @ApiResponse(code = 200, message = "success", response = HiddenPointVO.class),
            @ApiResponse(code = 200, message = "success", response = SectionVO.class),
            @ApiResponse(code = 200, message = "success", response = GnssDeviceVO.class)
    })
    public ResponseResult<Map<String, Object>> getSelectDownData(){
        Map<String, Object> res = gnssDataService.getSelectDownData("510521");
        return res != null?(ResponseResult<Map<String, Object>>) ResponseResult.success("查询成功", res) : (ResponseResult<Map<String, Object>>) ResponseResult.success("未查询到数据...", res);
    }


}
